module CarryLookaheadAdder4 (
	input [3:0] a,
	input [3:0] b,
	input cin,	  //carry_in
	input clk,    
	input cclr,
	output reg cout,
	output reg [3:0] sum
);

	wire [3:0] C;
	wire [3:0] G;
	wire [3:0] P;
	wire [3:0] t_sum;

	assign G[0] = a[0] & b[0];
	assign G[1] = a[1] & b[1];
	assign G[2] = a[2] & b[2];
	assign G[3] = a[3] & b[3];

	assign P[0] = a[0] | b[0];
	assign P[1] = a[1] | b[1];
	assign P[2] = a[2] | b[2];
	assign P[3] = a[3] | b[3];

	assign C[0] = G[0] | (P[0] & cin);
	assign C[1] = G[1] | (P[1] & G[0]) | (P[1] & P[0] & cin);
	assign C[2] = G[2] | (P[2] & G[1]) | (P[2] & P[1] & G[0]) | (P[2] & P[1] & P[0] & cin);
	assign C[3] = G[3] | (P[3] & G[2]) | (P[3] & P[2] & G[1]) | (P[3] & P[2] & P[1] & G[0]) | (P[3] & P[2] & P[1] & P[0] & cin);

	assign t_sum[0] = a[0] ^ b[0] ^ cin;
	assign t_sum[1] = a[1] ^ b[1] ^ C[0];
	assign t_sum[2] = a[2] ^ b[2] ^ C[1];
	assign t_sum[3] = a[3] ^ b[3] ^ C[2];

	always @ (posedge clk or negedge cclr) begin
		if (!cclr) begin 
			sum <= 0;
			cout = 0;
		end 
		else begin 
			sum <= t_sum;
			cout <= C[3];
		end
	end

endmodule
